<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
  <title>融资放款新增</title>
</head>
<style>
	.fieldset{
		margin-top: 5px;
		margin-bottom: 0px
	}
	.layui-legend{
		background-color:#5fb878;
		font-size:15px !important;
		width:140px;
	}
	.layui-form-item {
	    margin-bottom: 5px;
	    clear: both;
	    *zoom: 1;
	}
	.layui-form-label{width: 180px;}
	.right{
		float:right;
	}
	.width106{
		width:115px;
	}
	.width107{
		width:80px;
	}
</style>
<body>
<div class="layui-fluid">
    <div class="layui-card">
	    <div class="layui-tab-item layui-show">
	    	<div style="padding-top:15px;">&nbsp;</div>
			<form class="layui-form" id="addInfo_form" lay-filter="addInfo_form">
			<fieldset class="layui-elem-field layui-field-title fieldset"  id="baseInfo">
			<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">项目基础信息  ></legend>				
			  <div style="margin-top:20px">
			  	<div class="layui-form-item">
			  		<div class="layui-inline">
				      	<label class="layui-form-label">申请公司</label>
				      	<div class="layui-input-inline">
							<input type="hidden" name="hrOrgid" value="${bindOrgId}">
							<input type="text" value="${bindOrgName}" style="border:0px;width:220px" readonly="readonly" class="layui-input">
				      	</div>
				    </div>
				    <div class="layui-inline">
				    	<label class="layui-form-label">申请部门</label>
			      		<div class="layui-input-inline">
			      			<input type="hidden" name="hrDeptid" value="${bindDeptId}">
							<input type="text" value="${bindDeptName}" style="border:0px;" readonly="readonly" class="layui-input">
			      		</div>
				    </div>
			  	</div>
			  	<div class="layui-form-item">			  		
				    <div class="layui-inline">
				    	<label class="layui-form-label">申请人</label>
			      		<div class="layui-input-inline">
			        		<input type="hidden" name="hrStaffApplyid" value="${SESSION_KEY_USER_DETAIL.hrStaffId }">
			        		<input type="text" name="staffname" value="${staffName }" readonly="readonly" style="border:0px" autocomplete="off" class="layui-input">
			      		</div>
				    </div>
			    </div>
			  	<div class="layui-form-item">
			  		<div class="layui-inline">
					    <label class="layui-form-label">项目名称</label>
				      	<div class="layui-input-inline">
					      	<select id="add_select_proId" name="proname" lay-filter="add_select_proId" lay-verify="required" lay-search>
					      		<option value="">请选择-项目名称</option>
				      				<c:if test="${not empty allProName }">
				              			<c:forEach items="${allProName}" var="proNames">
				              				<option value="${proNames.proCode }">${proNames.proName }</option>
					            		</c:forEach>
				              		</c:if>
				      		</select>
				      	</div>
					</div>
					<div class="layui-inline">
				    	<label class="layui-form-label">融资合同名称</label>
				      	<div class="layui-input-inline">
					      	<select id="add_select_contractId" name="contractCode" lay-filter="add_select_contractId" lay-verify="required" lay-search>
				      		</select>
				      	</div>
				    </div>						
				</div> 
			</div>
			</fieldset>
			<fieldset class="layui-elem-field layui-field-title fieldset"  id="contractInfo">
			<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">合同信息  ></legend>				
			  	<div style="margin-top:20px">
					<div class="layui-form-item">
						<div class="layui-inline">
			            	<label class="layui-form-label">合同融资总额（万元）</label>
			            	<div class="layui-input-inline">
			            		<input type="text" id="finSum" name="finSum" readonly="readonly" style="border:0px" autocomplete="off" class="layui-input">
			            	</div>
		        		</div>
					</div>	
					<div style="margin-top:20px">
					  	<div class="layui-form-item">
						    <div class="layui-inline">
						    	<label class="layui-form-label" style="text-align:center;width:80px;">序号</label>
					      		<div class="layui-input-inline" style="width:50px;">
						      		<input type="text" value="" readonly="readonly" style="border:0px;" class="layui-input">
					      		</div>
						    </div>
						    <div class="layui-inline">
						      	<label class="layui-form-label" style="text-align:left;width:140px;">金融机构</label>
						      	<div class="layui-input-inline" style="width:50px;">
						        	<input type="text" value="" readonly="readonly" style="border:0px" class="layui-input">
						      	</div>
						    </div>
						    <div class="layui-inline">
						      	<label class="layui-form-label" style="text-align:left;width:140px;">融资团队负责人</label>
						      	<div class="layui-input-inline" style="width:50px;">
						        	<input type="text" value="" readonly="readonly" style="border:0px" class="layui-input">
						      	</div>
						    </div>	
						    <div class="layui-inline">
						      	<label class="layui-form-label" style="text-align:left;width:120px;">融资金额（万元）</label>
						      	<div class="layui-input-inline" style="width:50px;">
						        	<input type="text" value="" readonly="readonly" style="border:0px" class="layui-input">
						      	</div>
						    </div>					    
					    </div>
						<div id="finOrgRow">
					  		<div class="layui-form-item">
					    		<div class="layui-inline width106">
							    	<p style="text-align:center;"><label></label></p>
							    	<input type="hidden" name="finOrgIdx" value="1"/>
							    </div>
							    <div class="layui-inline">
							    	<label class="layui-form-label" style="width:30px;"></label>
						      		<div class="layui-input-inline">
							      		<input type="text" name="finOrg" value="" readonly="readonly" style="border:0px;width:220px;" autocomplete="off" class="layui-input">
						      		</div>
							    </div>
							    <div class="layui-inline">
							      	<label class="layui-form-label" style="width:0px;"></label>
							      	<div class="layui-input-inline">
							        	<input type="text" name="leader" value="" readonly="readonly" style="border:0px" autocomplete="off" class="layui-input">
							      	</div>
							    </div>
							    <div class="layui-inline">
							      	<label class="layui-form-label" style="width:0px;"></label>
							      	<div class="layui-input-inline">
							        	<input type="text" name="capAmounts" value="" readonly="readonly" style="border:0px" autocomplete="off" class="layui-input">
							      	</div>
							    </div>
						    </div>
			    		</div>
					</div>
				</div>
			</fieldset>
			<fieldset class="layui-elem-field layui-field-title fieldset"  id="loanInfo">
			<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">放款信息  ></legend>				
			  	<div style="margin-top:20px">
					<div class="layui-form-item">
					    <div class="layui-inline">
					    	<label class="layui-form-label">放款日期</label>
				      		<div class="layui-input-inline">
					      		<input type="text" placeholder="请选择放款日期" name="loanDate" id="loanDate" autocomplete="off" lay-verify="required" class="layui-input">
				      		</div>
					    </div>
					</div>
					<fieldset class="layui-elem-field layui-field-title fieldset"  id="loanDetail">
					<legend style="margin-left:40px;font-size:15px;font-weight:bold;">放款明细  ></legend>
						<div style="margin-top:20px" id="subDiv">
							<div class="layui-form-item">
								<div class="layui-inline">
							    	<label class="layui-form-label" style="text-align:right;width:50px;">序号</label>
						      		<div class="layui-input-inline" style="width:2px;">
							      		<input type="text" value="" readonly="readonly" style="border:0px" class="layui-input">
						      		</div>
							    </div>
							    <div class="layui-inline">
							      	<label class="layui-form-label" style="width:60px;">银行名称</label>
							      	<div class="layui-input-inline" style="width:80px;">
							        	<input type="text" value="" readonly="readonly" style="border:0px" class="layui-input">
							      	</div>
							    </div>
							    <div class="layui-inline">
							      	<label class="layui-form-label" style="width:95px;">支行/分行名称</label>
							      	<div class="layui-input-inline" style="width:45px;">
							        	<input type="text" value="" readonly="readonly" style="border:0px" class="layui-input">
							      	</div>
							    </div>	
							    <div class="layui-inline">
							      	<label class="layui-form-label" style="width:100px;">放款比例（%）</label>
							      	<div class="layui-input-inline" style="width:0px;">
							        	<input type="text" value="" readonly="readonly" style="border:0px" class="layui-input">
							      	</div>
							    </div>				
								<div class="layui-inline">
							      	<label class="layui-form-label" style="width:120px;padding-left:5px">放款金额（万元）</label>
							      	<div class="layui-input-inline" style="width:0px;">
							        	<input type="text" value="" readonly="readonly" style="border:0px" class="layui-input">
							      	</div>
							    </div>	
							    <div class="layui-inline">
							      	<label class="layui-form-label" style="width:100px;padding-left:0px">放款利率（%）</label>
							      	<div class="layui-input-inline" style="width:50px;">
							        	<input type="text" value="" readonly="readonly" style="border:0px" class="layui-input">
							      	</div>
							    </div>
						    </div>
					  		<div class="layui-form-item" id="loanRow1">
					  			<div class="layui-inline width107">
							    	<label class="layui-form-label" style="text-align:right;width:50px;">1</label>
						      		<div class="layui-input-inline" style="width:2px;">
							      		<input type="hidden" name="loanIdx" value="1" readonly="readonly" style="border:0px" class="layui-input">
						      		</div>
							    </div>
							    <div class="layui-inline">
							    	<label class="layui-form-label" style="width:0px;"></label>
						      		<div class="layui-input-inline" style="width:150px;">
							      		<input type="text" name="bankName" autocomplete="off" placeholder="请输入银行名称" maxlength="30" lay-verify="required|COC" class="layui-input">
						      		</div>
							    </div>
							    <div class="layui-inline">
							      	<label class="layui-form-label" style="width:10px;padding:5px;"></label>
							      	<div class="layui-input-inline" style="width:160px;">
							        	<input type="text" name="subBankName" autocomplete="off" placeholder="请输入支行/分行名称" maxlength="30" lay-verify="required|COC" class="layui-input">
							      	</div>
							    </div>
							    <div class="layui-inline">
							      	<label class="layui-form-label" style="width:0px;padding:5px;"></label>
							      	<div class="layui-input-inline" style="width:120px;">
							        	<input type="text" name="loanRatio" autocomplete="off" placeholder="请输入放款比例" onblur="isNumberAndFloat1(this);" lay-verify="required|floatAmount" class="layui-input">
							      	</div>
							    </div>
							    <div class="layui-inline">
							      	<label class="layui-form-label" style="width:0px;padding:3px;"></label>
							      	<div class="layui-input-inline" style="width:120px;">
							        	<input type="text" name="loanAmount" id="loanAmountInput-1" maxlength="11" autocomplete="off" onblur="calLoanAmount(this);arabiaToCN(this,2);" placeholder="请输入放款金额" lay-verify="required|floatAmount" class="layui-input">
							      	</div>
							    </div>
							    <div class="layui-inline">
							      	<label class="layui-form-label" style="width:0px;padding:3px;"></label>
							      	<div class="layui-input-inline" style="width:120px;">
							        	<input type="text" name="loanInterestRate" id="loanInterestRate-1" autocomplete="off" onblur="calLoanInterestRate(this)" placeholder="请输入放款利率" lay-verify="required|floatAmount" class="layui-input">
							      	</div>
							    </div>
							    <div class="layui-inline">
							    	<button type="button" class="layui-btn layui-btn-sm" id="addLoanBtn1" onclick="addLoanRow(this);"><i class="layui-icon">&#xe654;</i></button>
							    	<button type="button" class="layui-btn layui-btn-sm" style="display:none" id="delLoanBtn1" onclick="delLoanRow(1)"><i class="layui-icon">&#xe640;</i></button>
							    </div>
						    </div>
						    <div style="margin-top:20px">
						    	<div class="layui-form-item">
									<div class="layui-inline">
								    	<label class="layui-form-label" style="text-align:right;width:50px;">总计</label>
							      		<div class="layui-input-inline" style="width:2px;">
								      		<input type="text" value="" readonly="readonly" style="border:0px" class="layui-input">
							      		</div>
								    </div>
								    <div class="layui-inline">
								      	<label class="layui-form-label" style="width:0px;"></label>
								      	<div class="layui-input-inline" style="width:150px;">
								        	<input type="text" value="" readonly="readonly" style="border:0px" class="layui-input">
								      	</div>
								    </div>
								    <div class="layui-inline">
								      	<label class="layui-form-label" style="width:10px;padding:5px;"></label>
								      	<div class="layui-input-inline" style="width:160px;">
								        	<input type="text" value="" readonly="readonly" style="border:0px" class="layui-input">
								      	</div>
								    </div>	
								    <div class="layui-inline">
								      	<label class="layui-form-label" style="width:0px;padding:5px;"></label>
								      	<div class="layui-input-inline" style="width:100px;">
								        	<input type="text" value="" readonly="readonly" style="border:0px" class="layui-input">
								      	</div>
								    </div>				
									<div class="layui-inline">
								      	<label class="layui-form-label" style="width:0px;padding:3px;"></label>
								      	<div class="layui-input-inline" style="width:120px;">
								        	<input type="text" value="" id="totalCost" readonly="readonly" style="border:0px" class="layui-input">
								      	</div>
								    </div>	
								    <div class="layui-inline">
								      	<label class="layui-form-label" style="width:0px;padding:5px;"></label>
								      	<div class="layui-input-inline" style="width:120px;">
								        	<input type="text" value="" readonly="readonly" style="border:0px" class="layui-input">
								      	</div>
								    </div>
							    </div>	    
						    </div>	
						</div>			
					</fieldset>
				</div>
			</fieldset>
			<fieldset class="layui-elem-field layui-field-title fieldset"  id="finInfo">
	  			<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">融资信息 ></legend>
		  		<div style="margin-top:20px">		  		
					<div class="layui-form-item">
          				<div class="layui-inline">
					    <label class="layui-form-label">承贷企业</label>
					      	<div class="layui-input-inline">
						      	<select id="query-select-coopName" name="sgCoopId" lay-filter="query-select-coopName" lay-verify="required" lay-search>
						      		<option value="">请选择-承贷企业</option>
					      				<c:if test="${not empty coopInfoName }">
					              			<c:forEach items="${coopInfoName}" var="coops">
					              				<option value="${coops.id }">${coops.coopName }</option>
						            		</c:forEach>
					              		</c:if>
					      		</select>
					      	</div>
						</div>						
					</div>
					<div class="layui-form-item">
						<div class="layui-inline">
				    	<label class="layui-form-label">货款品种</label>
					    	<div class="layui-input-inline">
						    	<select id="add_select_loadType" name="loadType" lay-filter="add_select_loadType" lay-verify="required">
					      			<option value="">请选择-货款品种</option>
					              	<option value="1">项目贷款</option>
					              	<option value="2">流贷</option>
					              	<option value="3">银行承兑汇票</option>
					              	<option value="9">其他</option>
								</select>
							</div>
				    	</div>
					</div>	
					<div class="layui-form-item" id="creditAmount" style="display:none">
						<div class="layui-inline">
					    	<label class="layui-form-label">敞口金额（万元）</label>
				      		<div class="layui-input-inline">
					      		<input type="text" id="creditAmountInput" name="creditAmount" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>					    
					</div>
					<div class="layui-form-item" id="bondAmount" style="display:none">
						<div class="layui-inline">
					    	<label class="layui-form-label">保证金（万元）</label>
				      		<div class="layui-input-inline">
					      		<input type="text" id="bondAmountInput" name="bondAmount" maxlength="11" autocomplete="off" onblur="calTicketAmount(this);arabiaToCN(this,2);" lay-verify="required|floatAmount" class="layui-input">
				      		</div>
					    </div>					    
					</div>
					<div class="layui-form-item" id="ticketAmount" style="display:none">
						<div class="layui-inline">
					    	<label class="layui-form-label">开具银票金额（万元）</label>
				      		<div class="layui-input-inline">
					      		<input type="text" id="ticketAmountInput" name="ticketAmount" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>					    
					</div>										
					<div class="layui-form-item" id="capAmount" style="display:none">
					    <div class="layui-inline">
					    	<label class="layui-form-label">融资金额（万元）</label>
				      		<div class="layui-input-inline">
					      		<input type="text" id="capAmountInput" name="capAmount" lay-verify="required|floatAmount" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>
					</div>
					<div class="layui-form-item" id="ticketServiceFee" style="display:none">
						<div class="layui-inline">
					    	<label class="layui-form-label">开票手续费率（%）</label>
				      		<div class="layui-input-inline">
					      		<input type="text" id="ticketServiceRateInput" name="ticketServiceRate" placeholder="开票手续费率" maxlength="11" autocomplete="off" onblur="calTicketServiceFee(this);" lay-verify="required|floatAmount" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">开票手续费（万元）</label>
				      		<div class="layui-input-inline">
					      		<input type="text" id="ticketServiceFeeInput" name="ticketServiceFee" lay-verify="required|floatAmount" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">贴现利率（%）</label>
				      		<div class="layui-input-inline">
					      		<input type="text" id="ticketDiscountRateInput" name="ticketDiscountRate" placeholder="贴现利率" maxlength="11" autocomplete="off" onblur="isNumberAndFloat1(this);" lay-verify="required|floatAmount" class="layui-input">
				      		</div>
					    </div>
					</div>
					<div class="layui-form-item" id="otherLoadName" style="display:none">
					    <div class="layui-inline">
					    	<label class="layui-form-label">其他货款品种名称</label>
				      		<div class="layui-input-inline">
					      		<input type="text" id="otherLoadNameInput" name="otherLoadName" lay-verify="required" placeholder="其他货款品种名称" autocomplete="off" class="layui-input">
				      		</div>
					    </div>
					</div>	
					<div class="layui-form-item">
						<div class="layui-inline">
					    	<label class="layui-form-label">融资开始日期</label>
				      		<div class="layui-input-inline">
					      		<input type="text" name="capStartDate" placeholder="融资开始日期" id="sent-laydate-capStartDate" autocomplete="off" readonly lay-verify="required" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">融资结束日期</label>
				      		<div class="layui-input-inline">
					      		<input type="text" name="capEndDate" placeholder="融资结束日期"  id="sent-laydate-capEndDate" autocomplete="off" readonly lay-verify="required" class="layui-input">
				      		</div>
					    </div>
					</div>
					<div class="layui-form-item">
						<div class="layui-inline">
					    	<label class="layui-form-label">融资期限（天）</label>
				      		<div class="layui-input-inline">
					      		<input type="text" name="timeLimitDays" readonly="readonly" class="layui-input">
				      		</div>
					    </div>
					</div>
					<div class="layui-form-item">
						<div class="layui-inline">
					    	<label class="layui-form-label">放款利率（%）</label>
				      		<div class="layui-input-inline">
					      		<input type="text" name="loanRate" style="border:0px" readonly="readonly" class="layui-input">
				      		</div>
					    </div>
					</div>
					<div class="layui-form-item">
						<div class="layui-inline">
					    	<label class="layui-form-label">综合成本（%）</label>
				      		<div class="layui-input-inline">
					      		<input type="text" name="multiCostRate" autocomplete="off" onblur="isNumberAndFloat1(this);" lay-verify="required|floatAmount" class="layui-input">
				      		</div>
					    </div>					    
					</div>
					<div style="margin-top:20px"> 
						<div class="layui-form-item">						
					    	<label class="layui-form-label">综合成本备注</label>
					    	<div class="layui-input-block">
								<textarea name="multiCostMemo" class="layui-textarea" maxlength="1000" autocomplete="off"
									lay-verify="required" style="width:899px;height:90px;"></textarea>
							</div>					   
						</div>
					</div>
					<div style="margin-top:20px"> 
						<div class="layui-form-item">
						<label class="layui-form-label">资金监管要求</label>
							<div class="layui-input-block">
								<textarea name="requires" class="layui-textarea" maxlength="500"
									lay-verify="required" style="width:899px;height:90px;"></textarea>
							</div>
					   </div>
					</div>
					<div style="margin-top:20px">    
					    <div class="layui-form-item">
						<label class="layui-form-label">资金用款流程</label>
							<div class="layui-input-block">
								<textarea name="usageFlow" class="layui-textarea" maxlength="500"
									lay-verify="required" style="width:899px;height:90px;"></textarea>
							</div>
					 	</div> 
					</div>
				</div>
			</fieldset> 
		
			<fieldset class="layui-elem-field layui-field-title" style="margin-top: 15px;">
                 <legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">附件信息 ></legend>
                 <div style="margin-top:20px;">
	                 <div class="layui-form-item">
					    <label class="layui-form-label" style="width:350px;">支持pdf、excel、word、图片资料，可上传多个</label>
					</div>
	                 <div class="layui-form-item">
					    <label class="layui-form-label">附件资料（选填）</label>
					    <div class="layui-input-block">
					    	<div class="layui-upload">
				              	<button type="button" class="layui-btn" id="1-upload-more">上传</button>
		                		<div class="layui-upload-list" id="1-upload-more-list">
		                		</div>
				            </div>
					    </div>
				  	</div>
				  </div>
            </fieldset>	
                 		   
			<div class="layui-form-item" style="position: fixed ! important; right: 30px; bottom:45%;z-index:10000;">
				<div class="layui-input-block">
		      		<button class="layui-btn layui-bg-blue layui-btn-normal layui-btn-lg  layui-btn-radius" type="button" lay-submit lay-filter="addInfo_form_submit" id="addInfo_form_submit">
		      		<i class="layui-icon layui-icon-ok layuiadmin-button-btn"></i>
		      		提交
		      		</button>
		      	</div>
		    </div>
			</form>			
  		</div>
	</div>
</div>
  <script>
	//静态资源路径前缀
	var staticPath = '${fileHttpPre}';
	var stateJSON = <infopub:dicJson groupNo="A00010028" />;
	
  layui.config({
    base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'set', 'upload', 'element', 'laydate'], function(){
    var $ = layui.$
    ,form = layui.form
    ,element = layui.element
    ,laydate = layui.laydate
    ,upload = layui.upload;
    
    laydate.render({
	      elem: '#loanDate'
	});
    var capStart =laydate.render({
	      elem: '#sent-laydate-capStartDate'
    	  ,trigger: 'click'
		  ,done: function(value, date){
  	        //更新结束日期的最小日期
  	        capEnd.config.min = lay.extend({}, date, {
  	          month: date.month - 1
  	        });
  	        
  	        //自动弹出结束日期的选择器
  	       capEnd.config.elem[0].focus();
  	    }
	});
    var capEnd =laydate.render({
	      elem: '#sent-laydate-capEndDate'
	      ,trigger: 'click'
	      ,done:function(value, date){
	    	  //更新开始日期的最大日期
	  	      capStart.config.max = lay.extend({}, date, {
	  	          month: date.month - 1
	  	      });
	    	  calDate();
	      }
	});
       
 	// 正则校验
	form.verify({
		//验证汉字
	    CHS:[
	    	/^[\u0391-\uFFE5]+$/
	    	,'只能输入汉字'
	  	],
	  	//名字校验
	  	COC: [
			/^[\u4e00-\u9fa5_a-zA-Z0-9]+$/
			,'请输入正确的名称'
	  	],
	  	//大于0的正整数
	  	intNumber:[
			/^[1-9]\d*$/
			,'请输入正确的数字'
	  	],
	  	//数字只能有两位小数
	  	floatNumber:[
			/^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			,'请输入正确的数字'
	  	],
	  	telNumber:[/^[1][3,4,5,7,8,9][0-9]{9}$/
			  		,'请输入正确的号码'
		],
	  	//数字大于等于0，并只能有两位小数
	  	floatAmount:[
			/^([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			//var pattern=/^((\d+\.\d*[1-9]\d{1})|(\d*[1-9]\d*\.\d{2}))$/; 
			,'请输入正确的数字'
	  	]
	});
	//项目名称select监听
    form.on('select(add_select_proId)', function(data){
    	var id = data.value;
    	if(id==""||id==null){
    		$('select[id="add_select_contractId"]').html('');
    		form.render();
    	}else{
    		$('select[id="add_select_contractId"]').html('');
       		$('input[name="finSum"]').val('');  	
       		$('#finOrgRow').html('');
       		form.render();
       		getContractInfoByProId(id);  
    	}  		   			
    }); 
 	//融资合同select监听
    form.on('select(add_select_contractId)', function(data){
    	var id = data.value;
    	if(id==""||id==null){
    		$('input[name="finSum"]').val('');  	
    		$('#finOrgRow').html('');
    		form.render();
    	}else{
    		getBankByContractId(id);  
    	}  	
    }); 
  	//货款品种elect监听并统计放款利率
    form.on('select(add_select_loadType)', function(data){
    	var reg = /^([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;	
    	var id = data.value;
    	if(id==""||id==null){//为空时连带框均设置为空并隐藏
    		$('#creditAmount').hide();
    		$('#bondAmount').hide();
    		$('#ticketAmount').hide();
    		$('#capAmount').hide();
    		$('#ticketServiceFee').hide();
    		$('#otherLoadName').hide(); 		
    		$('input[name=creditAmount]').val('');
    		$('input[name=bondAmount]').val('');
    		$('input[name=ticketAmount]').val('');
    		$('input[name=capAmount]').val('');    		
    		$('input[name=ticketServiceRate]').val('');
    		$('input[name=ticketServiceFee]').val('');
    		$('input[name=ticketDiscountRate]').val('');
    		$('input[name=otherLoadName]').val('');    		
    		$("#creditAmountInput").removeAttr("lay-verify")
    		$("#bondAmountInput").removeAttr("lay-verify");
    		$("#ticketAmountInput").removeAttr("lay-verify");
    		$("#capAmountInput").removeAttr("lay-verify");  		
    		$("#ticketServiceRateInput").removeAttr("lay-verify")
    		$("#ticketServiceFeeInput").removeAttr("lay-verify");
    		$("#ticketDiscountRateInput").removeAttr("lay-verify");
    		$("#otherLoadNameInput").removeAttr("lay-verify");
    		form.render();
    	}else if(id=='3'){
    		$('#creditAmount').show();
    		$('#bondAmount').show();
    		$('#ticketAmount').show();
    		$('#ticketServiceFee').show();
    		$('#otherLoadName').hide(); 
    		$('#capAmount').hide();
    		$("#capAmountInput").removeAttr("lay-verify");
    		$("#otherLoadNameInput").removeAttr("lay-verify");
    		$("#creditAmountInput").attr("lay-verify","required|floatNumber");
    		$("#bondAmountInput").attr("lay-verify","required|floatNumber");
    		$("#ticketAmountInput").attr("lay-verify","required|floatNumber");
    		$("#ticketServiceRateInput").attr("lay-verify","required|floatNumber");
    		$("#ticketServiceFeeInput").attr("lay-verify","required|floatNumber");
    		$("#ticketDiscountRateInput").attr("lay-verify","required|floatNumber");
    		$('input[name=creditAmount]').val('');
    		$('input[name=bondAmount]').val('');
    		$('input[name=ticketAmount]').val('');
    		$('input[name=capAmount]').val('');
    		$('input[name=ticketServiceRate]').val('');
    		$('input[name=ticketServiceFee]').val('');
    		$('input[name=ticketDiscountRate]').val('');
    		$('input[name=otherLoadName]').val(''); 
    		
    		var creditAmountStr = $('#totalCost').val();
    		if(creditAmountStr==''||creditAmountStr==null||!reg.test(creditAmountStr)){
    			creditAmountStr =0;
    		}
    		$('input[name=creditAmount]').val(creditAmountStr);
    		var loanRateAll = 0;
			$("input[name='loanAmount']").each(function(){
				var loanAmount = $(this).val();
				if(loanAmount==''||loanAmount==null||!reg.test(loanAmount)){
					loanAmount =0;
				}					
				var curId = $(this).attr('id');
				var loanInterestRateId = 'loanInterestRate-'+ curId.split('-')[1];
				var loanInterestRate = $('#'+loanInterestRateId).val();
				if(loanInterestRate==''||loanInterestRate==null||!reg.test(loanInterestRate)){
					loanInterestRate = 0;
					$('#'+loanInterestRateId).val(0);
				}
				loanRateAll += loanAmount * (loanInterestRate/100);				
			});
			if(creditAmountStr==0){
				$("input[name='loanRate']").val(0);
			}else{
				var loanRate = ((loanRateAll/creditAmountStr)*100).toFixed(2);
				$("input[name='loanRate']").val(loanRate);	
			}	
    		form.render();
    	}else if(id=='9'){
    		$('#creditAmount').hide();
    		$('#bondAmount').hide();
    		$('#ticketAmount').hide();
    		$('#ticketServiceFee').hide();
    		$('#otherLoadName').show();
    		$('#capAmount').show();
    		$("#otherLoadNameInput").attr("lay-verify","required");
    		$("#capAmountInput").attr("lay-verify","required|floatNumber");
    		$('input[name=creditAmount]').val('');
    		$('input[name=bondAmount]').val('');
    		$('input[name=ticketAmount]').val('');
    		$('input[name=capAmount]').val('');
    		$('input[name=ticketServiceRate]').val('');
    		$('input[name=ticketServiceFee]').val('');
    		$('input[name=ticketDiscountRate]').val('');
    		$('input[name=otherLoadName]').val('');
    		$("#creditAmountInput").removeAttr("lay-verify");
    		$("#bondAmountInput").removeAttr("lay-verify");
    		$("#ticketAmountInput").removeAttr("lay-verify");
    		$("#ticketServiceRateInput").removeAttr("lay-verify");
    		$("#ticketServiceFeeInput").removeAttr("lay-verify");
    		$("#ticketDiscountRateInput").removeAttr("lay-verify");
    		
    		var capAmountStr = $('#totalCost').val();
    		if(capAmountStr==''||capAmountStr==null||!reg.test(capAmountStr)){
    			capAmountStr =0;
    		}
    		$('input[name=capAmount]').val(capAmountStr);
    		var loanRateAll = 0;
			$("input[name='loanAmount']").each(function(){
				var loanAmount = $(this).val();
				if(loanAmount==''||loanAmount==null||!reg.test(loanAmount)){
					loanAmount =0;
				}
				var curId = $(this).attr('id');
				var loanInterestRateId = 'loanInterestRate-'+ curId.split('-')[1];
				var loanInterestRate = $('#'+loanInterestRateId).val();
				if(loanInterestRate==''||loanInterestRate==null||!reg.test(loanInterestRate)){
					loanInterestRate = 0;
					$('#'+loanInterestRateId).val(0);
				}
				loanRateAll += loanAmount * (loanInterestRate/100);				
			});
			if(capAmountStr==0){
				$("input[name='loanRate']").val(0);
			}else{
				var loanRate = ((loanRateAll/capAmountStr)*100).toFixed(2);
				$("input[name='loanRate']").val(loanRate);	
			}
    		form.render();
    	}else{
    		$('#creditAmount').hide();
    		$('#bondAmount').hide();
    		$('#ticketAmount').hide();
    		$('#ticketServiceFee').hide();
    		$('#otherLoadName').hide();
    		$('#capAmount').show();
    		$("#capAmountInput").attr("lay-verify","required|floatNumber");
    		$('input[name=creditAmount]').val('');
    		$('input[name=bondAmount]').val('');
    		$('input[name=ticketAmount]').val('');
    		$('input[name=capAmount]').val('');
    		$('input[name=ticketServiceRate]').val('');
    		$('input[name=ticketServiceFee]').val('');
    		$('input[name=ticketDiscountRate]').val('');
    		$('input[name=otherLoadName]').val(''); 
    		
    		$("#creditAmountInput").removeAttr("lay-verify");
    		$("#bondAmountInput").removeAttr("lay-verify");
    		$("#ticketAmountInput").removeAttr("lay-verify");
    		$("#ticketServiceRateInput").removeAttr("lay-verify");
    		$("#ticketServiceFeeInput").removeAttr("lay-verify");
    		$("#ticketDiscountRateInput").removeAttr("lay-verify");
    		$("#otherLoadNameInput").removeAttr("lay-verify");
    		var capAmountStr = $('#totalCost').val();
    		if(capAmountStr==''||capAmountStr==null||!reg.test(capAmountStr)){
    			capAmountStr =0;
    		}
    		$('input[name=capAmount]').val(capAmountStr);
    		var loanRateAll = 0;
			$("input[name='loanAmount']").each(function(){
				var loanAmount = $(this).val();
				if(loanAmount==''||loanAmount==null||!reg.test(loanAmount)){
					loanAmount =0;
				}
				var curId = $(this).attr('id');
				var loanInterestRateId = 'loanInterestRate-'+ curId.split('-')[1];
				var loanInterestRate = $('#'+loanInterestRateId).val();
				if(loanInterestRate==''||loanInterestRate==null||!reg.test(loanInterestRate)){
					loanInterestRate = 0;
					$('#'+loanInterestRateId).val(0);
				}
				loanRateAll += loanAmount * (loanInterestRate/100);				
			});
			if(capAmountStr==0){
				$("input[name='loanRate']").val(0);
			}else{
				var loanRate = ((loanRateAll/capAmountStr)*100).toFixed(2);
				$("input[name='loanRate']").val(loanRate);	
			}
    		form.render();
    	}	
    }); 
	
	//多文件列表示例
    upload.render({
	      elem: '#1-upload-more'
	      ,url: basePath + '/loanFin/uploadAtt/'
	      ,data: {
	    	  types:1
	    		}
	      ,multiple: true
	      ,accept: 'file'
	      ,acceptMime: 'application/zip,application/x-rar-compressed,image/jpeg,image/png,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf'
	   	  ,before: function(obj){ //obj参数包含的信息
	   		    layer.load(); //上传loading
	   		  }
	      ,done: function(res){
	    	  //如果上传失败
	          if(res.code > 0){
	        	  
	        	  layer.closeAll('loading'); //关闭loading
	        	  return layer.msg(res.msg,{icon: 7});
	          }
	          //上传完毕
	   	  	  if(res.entity != null && res.entity.length > 0){
	   	  		
				for(var i in res.entity){
					var loanFin = res.entity[i];
					var arr = loanFin.split("|");
					var imgSrc = "";
					var suffix = arr[1].substring(arr[1].lastIndexOf(".")+1,arr[1].length);
					if(suffix == 'jpg' || suffix == 'png'){
						imgSrc = "${fileHttpPre}/"+arr[3];
					}else{
						imgSrc = "${ctx}/resources/images/"+suffix+".jpg";
					}
	        		$('#1-upload-more-list')
	        		.append('<div class="layui-upload-img-div" id="upload_img_'+arr[2]+'"><img src="'+imgSrc+'" title="'
	        				+ arr[1] +'" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\''+"${fileHttpPre}"
	        						+arr[3] +'\');">查看</a><a href="javascript:void(0)" onclick="del(\''
	        								+arr[2]+'\')";>删除</a></div><p>'+arr[1]+'</p><input type="hidden" value="'
	        								+loanFin+'" id="fileAtt_'+arr[2]+'" name="fileAtts" ></input></div> ');
				}
		  	  }
	      }
	      ,allDone: function(obj){ //当文件全部被提交后，才触发
	    	  layer.closeAll('loading'); //关闭loading
	      }
	      ,error: function(){
	    	  layer.closeAll('loading'); //关闭loading
	          //上传失败
	          layer.msg("上传失败，请稍后再试~",{icon: 7});
	        }
	    });
   	//监听提交
  	form.on('submit(addInfo_form_submit)', function(data){
  		$("#addInfo_form_submit").removeAttr("lay-submit").removeClass("layui-bg-blue").addClass("layui-btn-disabled");
  		layer.load();
       	//提交 Ajax 成功后，静态更新表格中的数据
       	console.log($('#addInfo_form').serialize());
       	$.ajax({
           	type : 'post',
			url : basePath + '/loanFin/save',
           	data: $('#addInfo_form').serialize(),
			success:function(result){
				if(result.success){
					layer.closeAll('loading'); //关闭loading
					layer.msg('提交单据成功~',{icon: 1});
					//两秒后关闭当前页面
					setTimeout(function(){
						/**
						 * 查找父菜单，并刷新
						 */
						var topDoc = $(window.top.document);
						var path = basePath + '/loanFin/list';
						// 获取页面名称
						var name = topDoc.find(".layui-nav-item [lay-href^='" + path + "']").text();
						if(name == '' || name == null){
							name = '融资放款';
						}
						window.parent.layui.index.openTabsPage(path, name);
						var iframe = window.parent.layui.admin.tabsBody(window.parent.layui.admin.tabsPage.index).find(".layadmin-iframe");
						iframe[0].contentWindow.location.reload(true);
						
						/**
						 * 关闭当前页
						 */
						var currPath = basePath + '/loanFin/add';
						var layid = topDoc.find("li[lay-id^='" + currPath + "']").attr('lay-id');
						window.parent.layui.element.tabDelete('layadmin-layout-tabs', layid);//关闭当前页
				        }, 2000);
				}else{
					layer.closeAll('loading'); //关闭loading
  					$("#addInfo_form_submit").removeClass("layui-btn-disabled").addClass("layui-bg-blue").attr("lay-submit","");
					layer.msg(result.msg,{icon: 7});
			  	}
			}
       	});
   	});  
 	// data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  	
  });
  var reg = /^([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;	
	//新增放款明细一行
	function addLoanRow(t){
		var $ = layui.$;
		var delBtnCount = $("button[id^='delLoanBtn']").length;
		if(delBtnCount == 1){
			$("button[id^='delLoanBtn']").each(function(){
				$(this).removeAttr("style");
			});
		}
		var thisid = $(t).attr("id").substring(10);
		thisid = $("div[id=loanRow" + thisid + "]").find("div:first").find("label").html();
		thisid = parseInt(thisid);
		var nextIndex = parseInt(thisid) + 1;
		var maxInd = $("div[id^='loanRow']").length;
		$("div[id^='loanRow']").each(function(){
			var tId = $(this).attr("id").substring(7);
			tId = parseInt(tId);
		  	if(tId > maxInd){
		  		maxInd = parseInt(tId);
		  	}
		  	var thisIndex = $(this).find("div:first").find("label").html();
		  	thisIndex = parseInt(thisIndex);
		  	var nextId = thisIndex + 1;
		  	if(thisIndex > thisid) {
		  		$("div[id=loanRow" + tId + "]").find("div:first").find("label").html(nextId);
		  	}
		});
		var ind = maxInd + 1;		
		var medalHtml = '';
		medalHtml += '	<div class="layui-form-item" id="loanRow'+ind+'">';
		medalHtml += '		<div class="layui-inline width107">';
		medalHtml += '			<label class="layui-form-label" style="text-align:right;width:50px;">'+nextIndex+'</label>'
		medalHtml += '			<div class="layui-input-inline" style="width:2px;">';
		medalHtml += '				<input type="hidden" name="loanIdx" value="'+nextIndex+'"/>';
		medalHtml += '			</div>';	
		medalHtml += '		</div>';
		medalHtml += '		<div class="layui-inline">';		    	
		medalHtml += '		<label class="layui-form-label" style="width:0px;"></label>';	    	
		medalHtml += '			<div class="layui-input-inline" style="width:150px;">';	    
		medalHtml += '				<input type="text" name="bankName" autocomplete="off" placeholder="请输入银行名称" maxlength="30" lay-verify="required|COC" class="layui-input">';	 	    
		medalHtml += '			</div>';	
		medalHtml += '		</div>';		    	
		medalHtml += '		<div class="layui-inline">';	      		
		medalHtml += '			<label class="layui-form-label" style="width:10px;padding:5px;"></label>';		      		
		medalHtml += '			<div class="layui-input-inline" style="width:160px;">';	      	
		medalHtml += '				<input type="text" name="subBankName" autocomplete="off" placeholder="请输入支行/分行名称" maxlength="30" lay-verify="required|COC" class="layui-input">';		   
		medalHtml += '			</div>';	
		medalHtml += '		</div>';		      	
		medalHtml += '		<div class="layui-inline">';	      	
		medalHtml += '			<label class="layui-form-label" style="width:0px;padding:5px;"></label>';	        	
		medalHtml += '			<div class="layui-input-inline" style="width:120px;">';	      
		medalHtml += '				<input type="text" name="loanRatio" autocomplete="off" placeholder="请输入放款比例" lay-verify="required|floatAmount" class="layui-input">';		  
		medalHtml += '			</div>';	
		medalHtml += '		</div>';	    
		medalHtml += '		<div class="layui-inline">';	      	
		medalHtml += '			<label class="layui-form-label" style="width:0px;padding:3px;"></label>';	      	
		medalHtml += '			<div class="layui-input-inline" style="width:120px;">';	        	
		medalHtml += '				<input type="text" name="loanAmount" id="loanAmountInput-'+nextIndex+'" autocomplete="off" onblur="calLoanAmount(this);arabiaToCN(this,2);" placeholder="请输入放款金额" lay-verify="required|floatAmount" class="layui-input">';	      	
		medalHtml += '			</div>';	
		medalHtml += '		</div>';	   
		medalHtml += '		<div class="layui-inline">';	      	
		medalHtml += '			<label class="layui-form-label" style="width:0px;padding:3px;"></label>';	      	
		medalHtml += '			<div class="layui-input-inline" style="width:120px;">';	        	
		medalHtml += '				<input type="text" name="loanInterestRate" id="loanInterestRate-'+nextIndex+'" autocomplete="off" onblur="calLoanInterestRate(this)" placeholder="请输入放款利率" lay-verify="required|floatAmount" class="layui-input">';	      	
		medalHtml += '			</div>';	
		medalHtml += '		</div>';	      	
		medalHtml += '		<div class="layui-inline">';	      
		medalHtml += '			<button type="button" class="layui-btn layui-btn-sm" id="addLoanBtn'+ind+'" onclick="addLoanRow(this);"><i class="layui-icon">&#xe654;</i></button>';	   
		medalHtml += '			<button type="button" class="layui-btn layui-btn-sm" id="delLoanBtn'+ind+'" onclick="delLoanRow('+ind+')"><i class="layui-icon">&#xe640;</i></button>';	    
		medalHtml += '		</div>';	
		medalHtml += '	</div>';	    	   	
			    
		$(t).parent().parent().after(medalHtml);
		layui.form.render();
	}
	
	//删除放款明细一行
	function delLoanRow(id){
		var $ = layui.$;
		layui.layer.confirm('确定删除？',{icon:3, title :'提示'}, function(index){
			
			var thisid = $("div[id=loanRow" + id + "]").find("div:first").find("label").html();
	    	thisid = parseInt(thisid);
	    	$("div[id^='loanRow']").each(function(){
				var tId = $(this).attr("id").substring(7);
				tId = parseInt(tId);
			  	var thisIndex = $("div[id=loanRow" + tId + "]").find("div:first").find("label").html();
			  	thisIndex = parseInt(thisIndex);
			  	var nextId = thisIndex - 1;
			  	if(thisIndex > thisid) {
			  		$("div[id=loanRow" + tId + "]").find("div:first").find("label").html(nextId);
			  	}
			});
	    	
			var strLoanAmount = $("div[id=loanRow" + id + "]").find("input[name='loanAmount']").val();		
			var totalCostStr = $('#totalCost').val();
			var totalCostNewStr = parseFloat(totalCostStr)-parseFloat(strLoanAmount);
			$('#totalCost').val(totalCostNewStr.toFixed(2));
			var totalCost = $('#totalCost').val();
			if(totalCost==''||totalCost==null||isNaN(totalCost)){
				$('#totalCost').val(0);
			}
			
			$("#loanRow"+id).remove();
			var delBtnCount = $("button[id^='delLoanBtn']").length;
			if(delBtnCount == 1){
				$("button[id^='delLoanBtn']").each(function(){
					$(this).attr("style","display:none");
				});
			}
			var loadType = $("select[name='loadType']").val();
			
			if(loadType=='3'){
				$("input[name='creditAmount']").val(totalCost);
				var strBondAmount =$("input[name='bondAmount']").val();
				if(strBondAmount==""||strBondAmount==null||strBondAmount==undefined){
					$("input[name='ticketAmount']").val('');
					$("input[name='ticketServiceFee']").val('');
				}else{
					var ticketAmount =  parseFloat(totalCost)+parseFloat(strBondAmount);
					$("input[name='ticketAmount']").val(ticketAmount.toFixed(2));
					var ticketServiceRateStr = $("input[name='ticketServiceRate']").val();
					if(ticketServiceRateStr!=''&&ticketServiceRateStr!=null){
						var ticketServiceFeeStr = parseFloat(ticketAmount)/100 * parseFloat(ticketServiceRateStr);
						$("input[name='ticketServiceFee']").val(ticketServiceFeeStr.toFixed(2));	
					}else{
						$("input[name='ticketServiceFee']").val('');
					}	
				}
				$("input[name='capAmount']").val('');
				var loanRateAll = 0;
				$("input[name='loanAmount']").each(function(){
					var loanAmount = $(this).val();
					if(loanAmount==''||loanAmount==null||!reg.test(loanAmount)){
						loanAmount =0;
					}				
					var curId = $(this).attr('id');
					var loanInterestRateId = 'loanInterestRate-'+ curId.split('-')[1];
					var loanInterestRate = $('#'+loanInterestRateId).val();	
					if(loanInterestRate==''||loanInterestRate==null||!reg.test(loanInterestRate)){
						loanInterestRate = 0;
						$('#'+loanInterestRateId).val(0);
					}
					loanRateAll += loanAmount * (loanInterestRate/100);				
				});
				if(totalCost==0){
					$("input[name='loanRate']").val(0);
				}else{
					var loanRate = ((loanRateAll/totalCost)*100).toFixed(2);
					$("input[name='loanRate']").val(loanRate);	
				}					
			}else if(loadType=='1'||loadType=='2'||loadType=='9'){
				$("input[name='creditAmount']").val('');
				$("input[name='bondAmount']").val('');
				$("input[name='ticketAmount']").val('');
				$("input[name='ticketServiceRate']").val('');
				$("input[name='ticketServiceFee']").val('');
	    		$("input[name='ticketDiscountRate']").val('');
				$("input[name='capAmount']").val(totalCost);
				var loanRateAll = 0;
				$("input[name='loanAmount']").each(function(){
					var loanAmount = $(this).val();
					if(loanAmount==''||loanAmount==null||!reg.test(loanAmount)){
						loanAmount =0;
					}	
					var curId = $(this).attr('id');
					var loanInterestRateId = 'loanInterestRate-'+ curId.split('-')[1];
					var loanInterestRate = $('#'+loanInterestRateId).val();
					if(loanInterestRate==''||loanInterestRate==null||!reg.test(loanInterestRate)){
						loanInterestRate = 0;
						$('#'+loanInterestRateId).val(0);
					}
					loanRateAll += loanAmount * (loanInterestRate/100);				
				});
				if(totalCost==0){
					$("input[name='loanRate']").val(0);
				}else{
					var loanRate = ((loanRateAll/totalCost)*100).toFixed(2);
					$("input[name='loanRate']").val(loanRate);	
				}	
			}else{
				var loanRateAll = 0;
				$("input[name='loanAmount']").each(function(){
					var loanAmount = $(this).val();
					if(loanAmount==''||loanAmount==null||!reg.test(loanAmount)){
						loanAmount =0;
					}	
					var curId = $(this).attr('id');
					var loanInterestRateId = 'loanInterestRate-'+ curId.split('-')[1];
					var loanInterestRate = $('#'+loanInterestRateId).val();	
					if(loanInterestRate==''||loanInterestRate==null||!reg.test(loanInterestRate)){
						loanInterestRate = 0;
						$('#'+loanInterestRateId).val(0);
					}
					loanRateAll += loanAmount * (loanInterestRate/100);				
				});
				if(totalCost==0){
					$("input[name='loanRate']").val(0);
				}else{
					var loanRate = ((loanRateAll/totalCost)*100).toFixed(2);
					$("input[name='loanRate']").val(loanRate);	
				}
				$("input[name='creditAmount']").val('');
				$("input[name='bondAmount']").val('');
				$("input[name='ticketAmount']").val('');
				$("input[name='capAmount']").val('');
				$("input[name='loanRate']").val('');
				$("input[name='ticketServiceRate']").val('');
				$("input[name='ticketServiceFee']").val('');
	    		$("input[name='ticketDiscountRate']").val('');
			}		
			layui.layer.close(index);			
 		});
	}
	
	//删除文件
	function del(index){
		layui.$("#fileAtt_"+index).remove();
		layui.$("#upload_img_"+index).remove();
	}
  
	//根据url查看文件
	function showImg(url){
		var openWin = window.open(url,'','left=410,height=768, width=1024, top=200,  toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
	}
  	
	//根据项目编号带出所有的项目下的融资合同
	function getContractInfoByProId(proCode){
		var $ = layui.$
	  	,form = layui.form
	  	
			//获取所有该项目信息
			$.ajax({
				type : "POST", //提交方式  
				url : "${ctx}/loanFin/getContractNameByProCode",//路径  
				data : {
					"proCode" :proCode
				},//数据，这里使用的是Json格式进行传输  
				success : function(result) {//返回数据根据结果进行相应的处理 
					if(result.flag==true){
						form.val('addInfo_form',result.contractNameList); // 填充原值
						var contractList = result.contractNameList;
						
						strContractBuffer="";
						strContractBuffer+= '<option value="">请选择</option>';
						layui.$.each(contractList, function(i,item){
							if(item.id != null && item.contractName != null){							
								strContractBuffer+=  '<option value='+item.id+'_'+item.contractName+'>'+item.contractName+'</option>';
							}
				        });
						$('#add_select_contractId').append(strContractBuffer);					
				        form.render();
					}else{
						layer.msg('数据通信异常~',{icon: 0});
					}
				} 
			});
		}
	
	//根据融资合同编号带出所有的融资合同下的合同信息
	function getBankByContractId(contractId){
		if(contractId == null || contractId == ''){
    		return;
    	}
		var $ = layui.$
	  	,form = layui.form
	  	
			//获取所有该项目信息
			$.ajax({
				type : "POST", //提交方式  
				url : "${ctx}/loanFin/getBankByContractId",//路径  
				data : {
					"contractCode" :contractId
				},//数据，这里使用的是Json格式进行传输  
				success : function(result) {//返回数据根据结果进行相应的处理 
					if(result.flag==true){
						form.val('addInfo_form',result.contractBankList); // 填充原值
						var finOrgList = result.contractBankList;
						
						var strBuffer ="";
						var strCapAmountBuffer = 0;
						$('#finOrgRow').html('');
						layui.$.each(finOrgList, function(ind,item){
							var i = ind + 1;
							strBuffer += '<div class="layui-form-item">';
							strBuffer += '<div class="layui-inline width106">';
							strBuffer += '<p style="text-align:center;"><label>'+i+'</label></p>';
							strBuffer += '<input type="hidden" name="finOrgIdx" value='+i+'/>';
							strBuffer += '</div>';	
							strBuffer += ' <div class="layui-inline">'; 
							strBuffer += ' <label class="layui-form-label" style="width:30px;"></label>'; 
							strBuffer += ' <div class="layui-input-inline">';    	
							strBuffer += ' <input type="text" name="finOrg" value='+finOrgList[ind].finOrg+' readonly="readonly" style="border:0px" autocomplete="off" class="layui-input">';    
							strBuffer += '</div>';	   
							strBuffer += '</div>';	    	
							strBuffer += ' <div class="layui-inline">'; 
							strBuffer += ' <label class="layui-form-label" style="width:0px;"></label>'; 
							strBuffer += ' <div class="layui-input-inline">';      		
							strBuffer += ' <input type="text" name="leader" value='+finOrgList[ind].leader+' readonly="readonly" style="border:0px" autocomplete="off" class="layui-input">';      		
							strBuffer += '</div>';	   
							strBuffer += '</div>';	    	
							strBuffer += ' <div class="layui-inline">'; 
							strBuffer += ' <label class="layui-form-label" style="width:0px;"></label>'; 
							strBuffer += ' <div class="layui-input-inline">';  		
							strBuffer += ' <input type="text" name="capAmounts" value='+finOrgList[ind].capAmount+' readonly="readonly" style="border:0px" autocomplete="off" class="layui-input">';       	
							strBuffer += '</div>';	   
							strBuffer += '</div>';        	
							strBuffer += '</div>';	   
							strCapAmountBuffer =  parseFloat(strCapAmountBuffer) + parseFloat(finOrgList[ind].capAmount);					
				        });
						$('#finOrgRow').html(strBuffer);					
						$('#finSum').val(strCapAmountBuffer.toFixed(2));	
				        form.render();
					}else{
						layer.msg('数据通信异常~',{icon: 0});
					}
				} 
			});
		}
	
	//计算放款明细总金额
	function calLoanAmount(num){
		var $ = layui.$		
		var strLoanAmount = 0;
		$("input[name='loanAmount']").each(function(){
			if(reg.test($(this).val())&&$(this).val()!=''){
				strLoanAmount = parseFloat(strLoanAmount)+ parseFloat($(this).val());
			}else{
				$(this).val(0);
				strLoanAmount = parseFloat(strLoanAmount)+ parseFloat($(this).val());
				layer.msg('请输入正确的数字，且保留两位小数！');
			}
				
		});
		$('#totalCost').val(strLoanAmount.toFixed(2));
		var totalCost = $('#totalCost').val();
		if(totalCost==''||totalCost==null){
			$('#totalCost').val(0);
		}
		var loadType = $("select[name='loadType']").val();
		
		if(loadType=='3'){
			var strBondAmount =$("input[name='bondAmount']").val();
			if(strBondAmount==""||strBondAmount==null||strBondAmount==undefined){
				$("input[name='ticketAmount']").val('');
				$("input[name='ticketServiceFee']").val('');
				$("input[name='creditAmount']").val(totalCost);
			}else{
				$("input[name='creditAmount']").val(totalCost);
				var ticketAmount =  parseFloat(totalCost)+parseFloat(strBondAmount);
				$("input[name='ticketAmount']").val(ticketAmount.toFixed(2));
				var ticketServiceRateStr = $("input[name='ticketServiceRate']").val();
				if(ticketServiceRateStr!=''&&ticketServiceRateStr!=null){
					var ticketServiceFeeStr = parseFloat(ticketAmount)/100 * parseFloat(ticketServiceRateStr);
					$("input[name='ticketServiceFee']").val(ticketServiceFeeStr.toFixed(2));	
				}else{
					$("input[name='ticketServiceFee']").val('');
				}
			}				
			$("input[name='capAmount']").val('');
			var loanRateAll = 0;
			$("input[name='loanAmount']").each(function(){
				var loanAmount = $(this).val();
				if(loanAmount==''||loanAmount==null||!reg.test(loanAmount)){
					loanAmount =0;
				}	
				var curId = $(this).attr('id');
				var loanInterestRateId = 'loanInterestRate-'+ curId.split('-')[1];
				var loanInterestRate = $('#'+loanInterestRateId).val();	
				if(loanInterestRate==''||loanInterestRate==null||!reg.test(loanInterestRate)){
					loanInterestRate = 0;
					$('#'+loanInterestRateId).val(0);
				}
				loanRateAll += loanAmount * (loanInterestRate/100);				
			});
			
			if(totalCost==0){
				$("input[name='loanRate']").val(0);
			}else{
				var loanRate = ((loanRateAll/totalCost)*100).toFixed(2);
				$("input[name='loanRate']").val(loanRate);	
			}	
		}else if(loadType=='1'||loadType=='2'||loadType=='9'){
			$("input[name='creditAmount']").val('');
			$("input[name='bondAmount']").val('');
			$("input[name='ticketAmount']").val('');
			$("input[name='ticketServiceRate']").val('');
			$("input[name='ticketServiceFee']").val('');
    		$("input[name='ticketDiscountRate']").val('');
			$("input[name='capAmount']").val(totalCost);
			var loanRateAll = 0;
			$("input[name='loanAmount']").each(function(){
				var loanAmount = $(this).val();
				if(loanAmount==''||loanAmount==null||!reg.test(loanAmount)){
					loanAmount =0;
				}	
				var curId = $(this).attr('id');
				var loanInterestRateId = 'loanInterestRate-'+ curId.split('-')[1];
				var loanInterestRate = $('#'+loanInterestRateId).val();	
				if(loanInterestRate==''||loanInterestRate==null||!reg.test(loanInterestRate)){
					loanInterestRate = 0;
					$('#'+loanInterestRateId).val(0);
				}
				loanRateAll += loanAmount * (loanInterestRate/100);				
			});
			if(totalCost==0){
				$("input[name='loanRate']").val(0);
			}else{
				var loanRate = ((loanRateAll/totalCost)*100).toFixed(2);
				$("input[name='loanRate']").val(loanRate);	
			}			
		}else{
			var loanRateAll = 0;
			$("input[name='loanAmount']").each(function(){
				var loanAmount = $(this).val();
				if(loanAmount==''||loanAmount==null||!reg.test(loanAmount)){
					loanAmount =0;
				}	
				var curId = $(this).attr('id');
				var loanInterestRateId = 'loanInterestRate-'+ curId.split('-')[1];
				var loanInterestRate = $('#'+loanInterestRateId).val();	
				if(loanInterestRate==''||loanInterestRate==null||!reg.test(loanInterestRate)){
					loanInterestRate = 0;
					$('#'+loanInterestRateId).val(0);
				}
				loanRateAll += loanAmount * (loanInterestRate/100);				
			});
			if(totalCost==0){
				$("input[name='loanRate']").val(0);
			}else{
				var loanRate = ((loanRateAll/totalCost)*100).toFixed(2);
				$("input[name='loanRate']").val(loanRate);	
			}
			$("input[name='creditAmount']").val('');
			$("input[name='bondAmount']").val('');
			$("input[name='ticketAmount']").val('');
			$("input[name='capAmount']").val('');
			$("input[name='loanRate']").val('');
			$("input[name='ticketServiceRate']").val('');
			$("input[name='ticketServiceFee']").val('');
    		$("input[name='ticketDiscountRate']").val('');
		}
		
	}
	//修改放款利率时重新计算放款利率
	function calLoanInterestRate(num){
		var $ = layui.$		
		var strLoanAmount = 0;
		$("input[name='loanAmount']").each(function(){
			if(reg.test($(this).val())&&$(this).val()!=''){
				strLoanAmount = parseFloat(strLoanAmount)+ parseFloat($(this).val());
			}else{
				$(this).val(0);
				strLoanAmount = parseFloat(strLoanAmount)+ parseFloat($(this).val());
				layer.msg('请输入正确的数字，且保留两位小数！');
			}
				
		});
		$('#totalCost').val(strLoanAmount.toFixed(2));
		var totalCost = $('#totalCost').val();
		if(totalCost==''||totalCost==null){
			$('#totalCost').val(0);
		}
		var loadType = $("select[name='loadType']").val();
		
		if(loadType=='3'){
			var strBondAmount =$("input[name='bondAmount']").val();
			if(strBondAmount==""||strBondAmount==null||strBondAmount==undefined){
				$("input[name='ticketAmount']").val('');
				$("input[name='ticketServiceFee']").val('');
				$("input[name='creditAmount']").val(totalCost);
			}else{
				$("input[name='creditAmount']").val(totalCost);
				var ticketAmount =  parseFloat(totalCost)+parseFloat(strBondAmount);
				$("input[name='ticketAmount']").val(ticketAmount.toFixed(2));
				var ticketServiceRateStr = $("input[name='ticketServiceRate']").val();
				if(ticketServiceRateStr!=''&&ticketServiceRateStr!=null){
					var ticketServiceFeeStr = parseFloat(ticketAmount)/100 * parseFloat(ticketServiceRateStr);
					$("input[name='ticketServiceFee']").val(ticketServiceFeeStr.toFixed(2));	
				}else{
					$("input[name='ticketServiceFee']").val('');
				}	
			}				
			$("input[name='capAmount']").val('');
			var loanRateAll = 0;
			$("input[name='loanAmount']").each(function(){
				var loanAmount = $(this).val();
				if(loanAmount==''||loanAmount==null||!reg.test(loanAmount)){
					loanAmount =0;
				}	
				var curId = $(this).attr('id');
				var loanInterestRateId = 'loanInterestRate-'+ curId.split('-')[1];
				var loanInterestRate = $('#'+loanInterestRateId).val();	
				if(loanInterestRate==''||loanInterestRate==null||!reg.test(loanInterestRate)){
					loanInterestRate = 0;
					$('#'+loanInterestRateId).val(0);
				}
				loanRateAll += loanAmount * (loanInterestRate/100);				
			});
			
			if(totalCost==0){
				$("input[name='loanRate']").val(0);
			}else{
				var loanRate = ((loanRateAll/totalCost)*100).toFixed(2);
				$("input[name='loanRate']").val(loanRate);	
			}	
		}else if(loadType=='1'||loadType=='2'||loadType=='9'){
			$("input[name='creditAmount']").val('');
			$("input[name='bondAmount']").val('');
			$("input[name='ticketAmount']").val('');
			$("input[name='ticketServiceRate']").val('');
			$("input[name='ticketServiceFee']").val('');
    		$("input[name='ticketDiscountRate']").val('');
			$("input[name='capAmount']").val(totalCost);
			var loanRateAll = 0;
			$("input[name='loanAmount']").each(function(){
				var loanAmount = $(this).val();
				if(loanAmount==''||loanAmount==null||!reg.test(loanAmount)){
					loanAmount =0;
				}	
				var curId = $(this).attr('id');
				var loanInterestRateId = 'loanInterestRate-'+ curId.split('-')[1];
				var loanInterestRate = $('#'+loanInterestRateId).val();	
				if(loanInterestRate==''||loanInterestRate==null||!reg.test(loanInterestRate)){
					loanInterestRate = 0;
					$('#'+loanInterestRateId).val(0);
				}
				loanRateAll += loanAmount * (loanInterestRate/100);				
			});
			if(totalCost==0){
				$("input[name='loanRate']").val(0);
			}else{
				var loanRate = ((loanRateAll/totalCost)*100).toFixed(2);
				$("input[name='loanRate']").val(loanRate);	
			}			
		}else{
			var loanRateAll = 0;
			$("input[name='loanAmount']").each(function(){
				var loanAmount = $(this).val();
				if(loanAmount==''||loanAmount==null||!reg.test(loanAmount)){
					loanAmount =0;
				}	
				var curId = $(this).attr('id');
				var loanInterestRateId = 'loanInterestRate-'+ curId.split('-')[1];
				var loanInterestRate = $('#'+loanInterestRateId).val();	
				if(loanInterestRate==''||loanInterestRate==null||!reg.test(loanInterestRate)){
					loanInterestRate = 0;
					$('#'+loanInterestRateId).val(0);
				}
				loanRateAll += loanAmount * (loanInterestRate/100);				
			});
			if(totalCost==0){
				$("input[name='loanRate']").val(0);
			}else{
				var loanRate = ((loanRateAll/totalCost)*100).toFixed(2);
				$("input[name='loanRate']").val(loanRate);	
			}
			$("input[name='creditAmount']").val('');
			$("input[name='bondAmount']").val('');
			$("input[name='ticketAmount']").val('');
			$("input[name='capAmount']").val('');
			$("input[name='loanRate']").val('');
			$("input[name='ticketServiceRate']").val('');
			$("input[name='ticketServiceFee']").val('');
    		$("input[name='ticketDiscountRate']").val('');
		}
		
	}
	
	//计算开具银票金额
	function calTicketAmount(num){
		var $ = layui.$;
		if (num.value == '' || num.value == null) {
			return;
		}
		if(reg.test(num.value)){
			var ticketAmountStr = parseFloat($("input[name='bondAmount']").val())+parseFloat($('#totalCost').val());
			$("input[name='ticketAmount']").val(ticketAmountStr.toFixed(2));
			var ticketServiceRateStr = $("input[name='ticketServiceRate']").val();
			if(ticketServiceRateStr!=''&&ticketServiceRateStr!=null){
				var ticketServiceFeeStr = parseFloat(ticketAmountStr)/100 * parseFloat(ticketServiceRateStr);
				$("input[name='ticketServiceFee']").val(ticketServiceFeeStr.toFixed(2));	
			}else{
				$("input[name='ticketServiceFee']").val('');
			}				
		}else{
			$("input[name='bondAmount']").val('');
			$("input[name='ticketAmount']").val('');
			layer.msg('请输入正确的数字，且保留两位小数！');
			return;
		}		
	}
	//计算开票手续费
	function calTicketServiceFee(num){
		var $ = layui.$;
		if (num.value == '' || num.value == null) {
			return;
		}
		if(reg.test(num.value)){
			var ticketServiceRateStr = num.value;
			var ticketAmountStr = $("input[name='ticketAmount']").val();
			if(ticketAmountStr!=''&&ticketAmountStr!=null){
				var ticketServiceFeeStr = parseFloat(ticketAmountStr)/100 * parseFloat(ticketServiceRateStr);
				$("input[name='ticketServiceFee']").val(ticketServiceFeeStr.toFixed(2));	
			}else{
				$("input[name='ticketServiceFee']").val('');
			}	
		}else{
			$("input[name='ticketServiceRate']").val(0);
			$("input[name='ticketServiceFee']").val(0);
			layer.msg('请输入正确的数字，且保留两位小数！');
			return;
		}		
	}
		
	//计算融资期限的天数
	function calDate(){
		var $ = layui.$
		,laydate = layui.laydate
		
		var startDate = $('#sent-laydate-capStartDate').val();
		var endDate = $('#sent-laydate-capEndDate').val();
		if(startDate!=''&&endDate!=''){
			var a1 = Date.parse(new Date(startDate));
		    var a2 = Date.parse(new Date(endDate));		   
		    var day = parseInt((a2-a1)/ (1000 * 60 * 60 * 24));//核心：时间戳相减，然后除以天数			
			$("input[name='timeLimitDays']").val(day + 1);
		}else{
			layer.msg('请先选择开始日期',{icon: 0});
			return;
		}		
	}
	//'请输入正确数字，且保留两位小数！'
	function isNumberAndFloat1(str) {
		var $ = layui.$, form = layui.form
		if (str.value == '' || str.value == null) {
			return;
		}
		var rgx = /^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;

		var boolrgx = rgx.test(str.value);// true 
		if (boolrgx) {
			return true;
		} else {
			str.value =0;
			layer.msg('请输入正确的数字，且保留两位小数！');
			return false;
		}
	}
  </script>
</body>
</html>

